package org.ricks.condition2.controller;

import org.ricks.condition2.Condition;
import org.ricks.condition2.ConditionBinder;
import org.ricks.condition2.event.ConditionCompletedEvent;
import org.ricks.ioc.anno.Bean;
import org.ricks.ioc.event.anno.EventReceiver;

import java.util.Optional;

@Bean
public class ConditionController {

    @EventReceiver
    public void onConditionCompleted(ConditionCompletedEvent event) {
        Condition cond = event.condition();
        String playerId = event.playerId();
        Optional.ofNullable(ConditionBinder.getInstance().getHandlers(cond)).ifPresent(handlers ->
                handlers.forEach(h -> h.accept(playerId, cond))
        );
    }
}
